import {
  getHotList,
  getNewList,
  getBanners
} from '../../utils/service.js'
var util = require('../../utils/util');
var common = require('../../utils/common');
var config = require('../../config/config');


Page({
  data: {
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    hostLists: [],
    newLists: [],
  },

  clList: function(e) {
    var dataset = e.target.dataset;
    var name = dataset.name;
    wx.navigateTo({
      url: '../search/search?name=' + name,
    })
  },
  search: function() {
    wx.navigateTo({
      url: '../search/search',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getHotList();
    this.getNewList();
    this.getNavlist(); 
    this.getBanners();

  },
  getBanners: function () {
    debugger
    var that = this;
    var params={};
    var appId = config.appId;
    params.appid = appId;
    params.type = 2;//搜索

    getBanners(params).then(res => {
      if (res) {
        that.setData({
          banners: res
        })
      }

    }).catch(e => {

    })
  },
  getNavlist: function () {

    let that = this;
    common.getNavlist(function (res) {
      var page = util.getCurrentPageUrl();
      for (var item in res) {

        if (res[item].pageUrl == page) {
          res[item].isSelect = true;
          break;
        }
      }
      that.setData({
        navs: res
      })
    });
  },
  getHotList: function() {
    var that = this;
    getHotList({}).then(res => {
      if (res) {
        that.setData({
          hostLists: res
        })
      }

    }).catch(e => {

    })
  },
  getNewList: function() {
    var that = this;
    debugger
    getNewList({}).then(res => {
      if (res) {
        that.setData({
          newLists: res,
        });
      }
    }).catch(e => {

    })

  },
  jumpPage: function (event) {

    var item = event.currentTarget.dataset.item;
    //用户点击
    if (item.jumpType != 4) {
      common.jumpClickData(item.appId);
    }

    common.jumpPage(event);
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getListNext()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {

  },

})